home *** CD-ROM | disk | FTP | other *** search
/ New Star Software Collection / NSS_Collection.iso / 3-004 ms visual basic pro 30 / 4.imz / 4.IMA / PERFORM.TX_ / PERFORM.bin
Text File  |  1993-04-28  |  19KB  |  410 lines

  1.  
  2.                   PERFORM.TXT
  3.  
  4.   Release Notes for Microsoft (R) Visual Basic (TM) Professional Edition
  5.  
  6.                   Version 3.00
  7.  
  8.          (C) Copyright Microsoft Corporation, 1993
  9.  
  10. This document contains performance tuning tips for Microsoft Visual Basic for
  11. Windows version 3.0 and Microsoft Access (TM) Relational Database Systems for  
  12. Windows version 1.1.
  13.  
  14. ------------------------
  15. How to Use This Document
  16. ------------------------
  17.  
  18. To view PERFORM.TXT on screen in Windows Notepad, maximize the Notepad window.
  19.  
  20. To print PERFORM.TXT, open it in Windows Write, Microsoft Word, or another word 
  21. processor.  Then select the entire document and format the text in 10-point
  22. Courier before printing.
  23.  
  24. ========
  25. Contents
  26. ========
  27.  
  28. Part    Description
  29. ----    -----------
  30.  1      Running Multiple Data Access Applications
  31.  2      Manipulating Secured Microsoft Access Databases
  32.  3      Tuning [ISAM] Entries in VB.INI or <APPNAME>.INI 
  33.  4      Using Transactions to Maximize Data Throughput
  34.  5      Minimizing Keyset Overhead When Working with Large Recordsets
  35.  6      Performance Tips for Visual Basic Data Access
  36.  
  37. =================================================
  38. Part 1: Running Multiple Data Access Applications
  39. =================================================
  40.  
  41. Visual Basic and Microsoft Access both use the same database engine to
  42. perform their database-related operations.  When these applications are run 
  43. at the same time on the same machine, it is important to coordinate use of
  44. the database engine, since it is only initialized by the first program 
  45. accessing a data access operation.  Re-initialization does not take place 
  46. until all programs using the database engine are ended and another started. 
  47.  
  48. Proper database initialization is especially important when accessing
  49. external databases like dBASE, FoxPro, Paradox, or Btrieve.  All of these 
  50. require special notations in the initialization file.
  51.  
  52. Note that data access applications can take the form of one or more 
  53. instances of:
  54.  
  55. - Microsoft Access
  56. - A Microsoft Access application
  57. - Visual Basic at design time
  58. - Visual Basic at run time
  59. - A Visual Basic application
  60.  
  61. For example, you might have a copy of Microsoft Access running with an 
  62. .EXE file created with Visual Basic.  On the other hand, you might have 
  63. two or more dissimilar applications running -- both of which need to 
  64. access the database engine.  You will need to make sure that the 
  65. initialization files are set up to deal with each of these situations. 
  66.  
  67. To ensure that all applications using the database engine function 
  68. as intended, you must ensure that all initialization parameters pertaining
  69. to external databases are identified in various .INI files under 
  70. section headings (such as [Installable ISAM], [Paradox Isam], [Btrieve 
  71. ISAM]) and are copied into each of the .INI files pertaining to each 
  72. data access application that can potentially be running at the same time. 
  73. The list below shows where each program looks for its initialization 
  74. information: 
  75.  
  76. Program                           .INI file
  77. =======                           ==========
  78. Microsoft Access                  MSACCESS.INI
  79. Microsoft Access application      MSACCESS.INI
  80. Visual Basic at design time       VB.INI
  81. Visual Basic at run time          VB.INI
  82. Visual Basic .EXE application      <APPNAME>.INI
  83.  
  84. All of these .INI files are located in your Windows directory.  During 
  85. development, your Visual Basic application defaults to VB.INI unless 
  86. your application uses the SetDataAccessOption statement to indicate 
  87. a specific .INI file location.  Once you create an executable program
  88. with Visual Basic, the initialization file will default to 
  89. <APPNAME>.INI unless you use SetDataAccessOption.
  90.  
  91. If you want to coordinate operations between an instance of a Visual 
  92. Basic application (or .EXE), you will want to force Visual Basic to 
  93. indicate the same initialization file that a second instance of your 
  94. program or an instance of Microsoft Access will use. This way, 
  95. regardless of which application starts (and initializes) the database 
  96. engine, both applications will be using the same initialization parameters.  
  97.  
  98. =======================================================
  99. Part 2: Manipulating Secured Microsoft Access Databases
  100. =======================================================
  101.  
  102. For Visual Basic to manipulate secured Microsoft Access databases,
  103. you must provide Visual Basic with the location of the SYSTEM.MDA file 
  104. associated with that Microsoft Access database, a valid user name, and 
  105. password. This can be accomplished in three steps:
  106.  
  107. 1)  Use the SetDataAccessOptions statement to point to a valid .INI file.
  108. 2)  Include a path to the SystemDB with a valid VB.INI or <appname>.INI
  109.     entry to locate the file.  For example:
  110.  
  111.          [Options]
  112.          SystemDB=C:\ACCESS\SYSTEM.MDA
  113.  
  114. 3) Set the user name and password (if other than "admin" with no password) 
  115.    with the SetDefaultWorkspace statement.
  116.  
  117. ========================================================
  118. Part 3: Tuning [ISAM] Entries in VB.INI or <APPNAME>.INI
  119. ========================================================
  120.  
  121. You can enhance the database access performance of Visual Basic by: 
  122.  
  123. - Adding or changing entries in the VB.INI or <APPNAME>.INI 
  124.   initialization file 
  125. - Using transactions  
  126.  
  127. Visual Basic automatically provides default internal settings for most 
  128. common database operations.  However, advanced users may want to tune these 
  129. settings to provide maximum performance for a particular system 
  130. configuration or application. 
  131.  
  132. Setup automatically installs <APPNAME>.INI in your Windows directory.  These 
  133. [ISAM] entries determine the sizes of data page and read-ahead caches in 
  134. memory, the amount of time data is held in a page cache, and the number of 
  135. times Visual Basic will retry a lock operation.
  136.  
  137. WARNING 
  138. -------
  139. Determining the best settings for your system configuration or application 
  140. can be time-consuming and difficult, usually involving much trial and error.  
  141. In addition, settings that seem optimal for one situation may not be optimal 
  142. for others. Casual users should not try to edit these entries.
  143.  
  144. Visual Basic automatically includes a PageTimeout entry in the [ISAM] section 
  145. of the VB.INI or <APPNAME>.INI file.  This entry sets the amount of time 
  146. Visual Basic holds a data page in memory.  For additional performance tuning, 
  147. you can add MaxBufferSize, ReadAheadPages, LockRetry, and CommitLockRetry 
  148. entries to this section. 
  149.  
  150. Visual Basic reads these initialization settings at startup time.  They can 
  151. be changed while Visual Basic is running, but the changes won't take effect 
  152. until you restart Visual Basic or your application.  As with all .INI 
  153. settings that affect the database engine, these settings are fixed once the 
  154. engine is initialized just before the first data access operation. 
  155.  
  156. PageTimeout Entry (Shared Data Only)
  157. ------------------------------------
  158. The PageTimeout entry sets the amount of time, in tenths of a second, that 
  159. Visual Basic holds a data page in a memory "page cache" if the database has 
  160. been opened for shared access.  Visual Basic reads data in 2K blocks of 
  161. records, or "pages."
  162.  
  163. For example, when Visual Basic reads a data page, it places the data in the 
  164. page cache.  If Visual Basic receives another read request for the same data 
  165. page during the timeout period, it reads the data directly from the page 
  166. cache rather than from disk.
  167.  
  168. Note 
  169. ----
  170. Access Basic ignores the PageTimeout setting unless your code allows 
  171. background processing by periodically calling the DoEvents statement or 
  172. function.
  173.  
  174. PageTimeOut Settings
  175. --------------------
  176. Maximum: 2147483647 (max Long integer) 
  177. Minimum: 0    
  178. Default: 300 
  179.  
  180. If you remove the PageTimeout entry, Visual Basic uses a default PageTimeout 
  181. setting of 5.  For example: 
  182.  
  183.      PageTimeout=20     ; This example sets PageTimeout to 2 seconds.
  184.  
  185. MaxBufferSize Entry 
  186. -------------------
  187. The MaxBufferSize entry sets the amount of memory, in kilobytes, reserved for 
  188. use as a page cache.  Visual Basic reads data in 2K pages, placing the data 
  189. in the page cache.  Once the data is placed in the cache, Visual Basic can 
  190. use it wherever it is needed -- in tables, queries, forms, or reports. 
  191.  
  192. When Visual Basic receives a read request, it first checks the data pages in 
  193. the page cache.  If the page isn't in the cache, Visual Basic reads the data 
  194. page from disk and then places it in the page cache.  Visual Basic uses 
  195. physical memory and if necessary virtual memory to create the cache.  All 
  196. pages stay in the cache until it is full and pages need to be flushed to 
  197. make room for new reads.
  198.  
  199. MaxBufferSize Settings
  200. ----------------------
  201. Maximum: 4096
  202. Minimum: 18 
  203. Default: If there is no MaxBufferSize entry in your VB.INI or <APPNAME>.INI 
  204.      file, Visual Basic uses a default setting of 512.
  205.  
  206. Note 
  207. ----
  208. Because Visual Basic reads data in 2-kilobyte pages, it always uses an even 
  209. MaxBufferSize setting.  If you type an odd number, Visual Basic uses a 
  210. MaxBufferSize setting of one less than the number.  For example: 
  211.  
  212.      MaxBufferSize=4096  ; This example sets MaxBufferSize to 4 MB.
  213.  
  214. ReadAheadPages Entry
  215. --------------------
  216. The ReadAheadPages entry sets the size, in data pages, of a "read-ahead" 
  217. cache used by Visual Basic for sequential page reads.  A sequential page read 
  218. occurs when Visual Basic detects that data in a current read request is on a 
  219. data page adjacent on physical disk to the data page of the previous request. 
  220. Visual Basic uses the "read-ahead" cache only when it detects that a 
  221. sequential read is taking place.  
  222.  
  223. - If Visual Basic detects a sequential page read, it reads the requested page 
  224.   plus the next (N-1) pages in that direction, where N is the ReadAheadPages 
  225.   setting, placing the data pages in the read-ahead cache.  
  226. - If Visual Basic then detects a sequential read, it can make the next N 
  227.   reads directly from the read-ahead cache.
  228.  
  229. The read-ahead cache increases the speed of sequential reads, especially for 
  230. reading data stored on a network. It increases record updates per second 
  231. (throughput) on a network by sending a few large packets rather than many 
  232. small packets over the network.  If possible, Visual Basic places the read-
  233. ahead cache in the first 640K of memory in order to benefit from the ability 
  234. of Windows to read from and write to conventional memory.  If the read-ahead 
  235. cache can't be placed in conventional memory, Visual Basic places it in high 
  236. memory.  Placing the cache in high memory is less efficient than placing it 
  237. in conventional memory because Windows must copy all reads and writes to its 
  238. own buffer before completing the memory operation. 
  239.  
  240. ReadAheadPages Settings
  241. -----------------------
  242. Maximum: 31 
  243. Minimum: 0 
  244. Default: If there is no ReadAheadPages entry in your VB.INI or <APPNAME>.INI 
  245.      file, Visual Basic uses a default setting of 8. For example: 
  246.           
  247.           ReadAheadPages = 16
  248.  
  249. Note
  250. ----
  251. Visual Basic creates a separate read-ahead cache for each database open on 
  252. your computer.  Each library database has its own read-ahead cache.
  253.  
  254. LockRetry Entry
  255. ---------------
  256. The LockRetry entry sets the number of times Visual Basic retries a page-
  257. locking operation before it reports an error.  For example, if a user tries 
  258. to lock a data page that is already locked by another user, the attempt will 
  259. fail.  Visual Basic will try to lock the page N more times, where N is the 
  260. LockRetry setting.  If the attempt to lock the page still fails on the Nth 
  261. retry, Visual Basic reports an error. 
  262.  
  263. LockRetry Settings
  264. ------------------
  265. Maximum: 2147483647 (max Long integer) 
  266. Minimum: 0 
  267. Default: If there is no LockRetry entry in your VB.INI or <APPNAME>.INI file, 
  268.      Visual Basic uses a default setting of 20. For example: 
  269.           
  270.           LockRetry = 6
  271.  
  272. CommitLockRetry Entry 
  273. ---------------------
  274. The CommitLockRetry entry is used with the LockRetry entry to set the number 
  275. of retries that Visual Basic attempts when a user tries to lock a record on a 
  276. data page already locked by a transaction.  If a user tries to lock a data 
  277. page that is already locked by a transaction, Visual Basic will try to lock 
  278. the page N more times, where N is the product of the LockRetry setting and 
  279. the CommitLockRetry setting.  For example, if the LockRetry setting is 5 and 
  280. the CommitLockRetry is 6, Visual Basic will try to lock the page 30 more 
  281. times.
  282.  
  283. CommitLockRetry Settings
  284. ------------------------
  285. Maximum: 2147483647 (max Long integer) 
  286. Minimum: 0 
  287. Default: If there is no CommitLockRetry entry in your VB.INI or <APPNAME>.INI 
  288.      file, Visual Basic uses a default setting of 20.  For example:
  289.          
  290.          CommitLockRetry = 6   ; Assuming a LockRetry setting of 6, 
  291.                    ; this example causes Visual Basic to 
  292.                    ; retry a page locked by a transaction 36 
  293.                    ; times.
  294.  
  295. ======================================================
  296. Part 4: Using Transactions to Maximize Data Throughput 
  297. ======================================================
  298.  
  299. In a multiuser environment, you can further tune the performance of Visual 
  300. Basic by using transactions for operations that update data.  A transaction 
  301. is a series of operations that must execute as a whole or not at all.  You 
  302. mark the beginning of a transaction with the BeginTrans statement.  You use 
  303. the Rollback or CommitTrans statement to end a transaction.  
  304.  
  305. You can usually increase the record updates per second (throughput) of an 
  306. application by placing operations that update data within an Access Basic 
  307. transaction. 
  308.  
  309. Tip
  310. ---
  311. Because Visual Basic locks data pages used in a transaction until the 
  312. transaction ends, using transactions will prevent access to those data pages 
  313. while the transaction is pending.  If you use transactions, try to find a 
  314. balance between data throughput and data access.
  315.  
  316. =====================================================================
  317. Part 5: Minimizing Keyset Overhead When Working with Large Recordsets
  318. =====================================================================
  319.  
  320. When a query selects a large number of records from the database, Visual 
  321. Basic only fetches the first row of that Dynaset or Snapshot and places the 
  322. key to refetch that row in memory.  Once a record is fetched or visited, it 
  323. becomes a member of the recordset.  As you "visit" additional rows of the 
  324. recordset, the keys are stored in workstation memory (in a temporary table), 
  325. and in the case of Snapshots, so is the data.  If you move back to previously
  326. fetched rows, Visual Basic refetches the rows using the old key fetched from 
  327. the temporary key table.  
  328.  
  329. - If the database record is no longer there, you will get a trappable error.  
  330. - If the record has changed, the new information is fetched from the 
  331.   database. 
  332.  
  333. As you move further and further into the recordset, more and more memory is 
  334. taken up storing the keys.  Eventually, Visual Basic will begin saving the 
  335. keyset on disk.  If this happens, space is used on disk in the directory 
  336. specified by your \TEMP environment variable.  Generally, you won't see a
  337. performance degradation until Visual Basic has to swap the keyset temporary 
  338. table to disk.  If you run out of disk space because Visual Basic has 
  339. exhausted the space in your \TEMP directory, you will get a trappable error. 
  340.  
  341. Moving to the end of the Dynaset or Snapshot does at least two things: 
  342. First, it forces Visual Basic to visit all of the records in your recordset. 
  343. Hence, all keys will be saved on the workstation.  If this is a few hundred 
  344. rows, this may not take long or take up more space than the workstation can 
  345. handle.  
  346.  
  347. However, for larger recordsets, a MoveLast operation may be far more than 
  348. the workstation can save.  When working with Snapshots, not only are the 
  349. keys fetched, but the data for all records is also brought into local 
  350. memory. Generally, you should avoid operations that fetch more rows than 
  351. your user or workstation can deal with.  Operations that must touch each 
  352. record in a recordset may best be performed with an action query that 
  353. consumes less system resources.  In any case, your performance will not be
  354. severely degraded, either as you move forward until you have to swap, or 
  355. hardly at all if you move backwards in the recordset -- even to the first 
  356. record. 
  357.  
  358. Note 
  359. ----
  360. The Dynaset or Snapshot membership is not set until the record is actually 
  361. fetched for the first time.  Since this can take from seconds to days 
  362. depending on how fast you fetch the records (moving down through the 
  363. recordset with MoveNext or with MoveLast), no Dynaset or Snapshot is really a 
  364. frozen subset of the data at a point in time.  The only way to ensure that 
  365. no changes are made while the recordset is built is to get exclusive access 
  366. to the table or database before fetching -- which essentially locks out all 
  367. other users until the recordset (or database) is closed.
  368.  
  369. =====================================================
  370. Part 6: Performance tips for Visual Basic Data Access  
  371. =====================================================
  372.  
  373. The following tips are suggested for operations involving more than just a 
  374. few records to increase the overall performance of your system.
  375.  
  376. 1) When working with large recordsets (Dynasets or Snapshots), do not use 
  377.    the MoveLast method unless absolutely necessary. 
  378.  
  379.    Moving to the end of a recordset requires Visual Basic to load all keys 
  380.    for the recordset into memory. In the case of Snapshots, not only are the 
  381.    keys loaded into memory, but the data is also brought into workstation 
  382.    memory.  If temporary memory space is exhausted, Visual Basic may be 
  383.    forced to swap this temporary cache to disk.  In this case, Visual Basic 
  384.    will use space as addressed by the \TEMP environment variable.  Once this 
  385.    space is exhausted, your application will trigger a trappable error.
  386.  
  387. 2) When you want to access external tables fast, attach the table to your 
  388.    database instead of using the IN clause in a SQL statement or addressing 
  389.    the table directly.  
  390.    
  391.    When Visual Basic needs to access your external table, all linkage 
  392.    information is resolved when the database is opened and does not have to 
  393.    be re-established and initialized each time the data is accessed (for  
  394.    example, with non-attached tables.
  395.  
  396. 3) For reasonably small recordsets, especially where you do not intend
  397.    to write to the recordset, use Snapshots instead of Dynasets.
  398.  
  399.    If possible, set the READONLY flag on the data control or DB_READONLY 
  400.    option when opening databases.  This will permit Visual Basic to bypass
  401.    significant logic to handle multi-user read-write access to your tables.
  402.  
  403. 4) In cases where you are working with external ODBC databases, you will
  404.    achieve maximum possible speed if you use SQL Passthrough instead of 
  405.    attaching or direct access that involves the Visual Basic database engine.
  406.  
  407.  
  408.  
  409.  
  410.